package com.example.anodemo.mapper;

import com.example.anodemo.model.Order;
import com.example.anodemo.model.OrderDetail;
import com.example.anodemo.model.Product;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class ProductMapperTestor {

    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private OrderMapper orderMapper;


    @Test
    public  void  testSelectAll(){

        List<Product> list = productMapper.selectAll();
        System.out.println(list);
    }


    @Test
    public void testSelectById(){
        Product product = productMapper.selectById(1);

        System.out.println(product);
    }


    @Test
    public  void  testInsert(){
          Product product  = new Product();
          product.setName("test002");
          product.setPrice(230.0);

          int affected= productMapper.insert(product);

        System.out.println(affected);
    }



    @Test
    public  void  testSelectOneToOne(){


        Product product = productMapper.selectById(1);

        System.out.println(product.getProductType().getDisplay());
    }


    @Test
    public void testSelectOneToMany(){

        Order order = orderMapper.selectById(1);
        List<OrderDetail> list = order.getOrderDetailList();

        System.out.println(list);

    }
}
